<script>
var slength = 140
$(function(){
	$(".zhuanfa").click(function(){
		
		var thiss = $(this).parent().parent().next('.zhuanfa_li');
		if ($(thiss).css('display') == 'none')
		{
			$(thiss).next('.pinglun_li').hide(300);
			$(thiss).show(300,function(){
				var text = $(thiss).children().children('.weibo_zhuanfa').children('textarea');
				
				$(text).focus();
				
				
			})
		}
		else
		{
			$(thiss).hide(300);
		}
	})
	
	$(".pinglun").click(function(){
	
		var thiss = $(this).parent().parent().next('.zhuanfa_li');
		if ($(thiss).next('.pinglun_li').css('display') == 'none')
		{
			$(thiss).hide(300);
			$(thiss).next('.pinglun_li').show(300,function(){
				$(thiss).next('.pinglun_li').children().children('.weibo_zhuanfa').children('textarea').focus();
				var ids = $(thiss).next('.pinglun_li').children().children('.weibo_zhuanfa').children('.zhuanfa_ps').children('.ids').val();
				
				$.post('/weibo/comment_list/'+ids+'/',function(data){
					//alert(data);
					var data=eval("("+data+")");
					$(thiss).next('.pinglun_li').children().children('.weibo_zhuanfa').children('.comment_list').children('ul').empty();
					$(data).each(function(key,val){
						//alert(key);
						$(thiss).next('.pinglun_li').children().children('.weibo_zhuanfa').children('.comment_list').children('ul').prepend('<li class="li"><img src="'+val['head']+'/50"/><p><a href="#">'+val['nick']+'</a>: '+val['text']+' </p><a href="javascript:" onclick="$(\'.cid_'+ids+'\').val('+val['id']+');$(\'.comment_'+ids+'\').val(\'回复@'+val['nick']+':\').focus()" class="right" class="comment">回复</a></li>');
					})
					
					
				})
				
				
			})
		}
		else
		{
			$(thiss).next('.pinglun_li').hide(300);
		}
	})
	
	$(".zhuanfa_body").keydown(function(){
		slength_t($(this));
	})
	
	$(".del_zhuanfa").click(function(){
		$(this).parent().next('textarea').val('').focus();
	})
	
	/* 转发 */
	$(".form1").submit(function(){
		var form = $(this);
		$(this).children().children().children('.zhuanfa_but').val('转发中...').attr('disabled',true)
		//tb_load();
		$.post($(this).attr('action'),$(this).serialize(),function(data){
			if (data == '-1')
			{
				$(form).children().children('.zhuanfa_tips').html('转发失败...');
				$(form).children().children('.zhuanfa_ps').children('.zhuanfa_but').val('转发').attr('disabled',false)
				return false;
			}
			$(form).children().children('.zhuanfa_ps').children('.zhuanfa_but').val('转发成功')
			var data = $(data).hide();
			$(".weibos").prepend(data);
			$(data).slideDown(600,function(){
				$(form).parent().slideUp(300)
				$(form).children().children('.zhuanfa_ps').children('.zhuanfa_but').val('转发').attr('disabled',false)
			});
		})
		return false;
	})
	
	/* 评论 */
	$(".form2").submit(function(){
		var form = $(this);
		ids = $(this).find('input[name=id]').val();
		
		$(this).children().children(".zhuanfa_ps").children('.button_blue').val('评论中...').attr('disabled',true);
		$.post($(this).attr('action'),$(this).serialize(),function(data){
			//alert(data);
			if (data == '-1')
			{
				$(form).children().children('.zhuanfa_tips').html('评论失败...');
				$(form).children().children('.zhuanfa_ps').children('.button_blue').val('评论').attr('disabled',false);
				return false;
			}
			
			var val=eval("("+data+")");
			$(form).children().children('.comment_list').children('ul').prepend('<li class="li"><img src="'+val['head']+'/50"/><p><a href="#">'+val['nick']+'</a>: '+val['text']+' </p><a href="javascript:" onclick="$(\'.cid_'+ids+'\').val('+val['id']+');$(\'.comment_'+ids+'\').val(\'回复@'+val['nick']+':\').focus()" class="right" class="comment">回复</a></li>');
			
			$(form).children().children('.zhuanfa_ps').children('.button_blue').val('评论').attr('disabled',false);
			
		})
		return false;
	})
	
	
	/* 点击显示大图 */
	$(".litpic").toggle(function(){
		$(this).css('text-align','center')
		var src = $(this).attr('alt');
		$(this).children('img').attr('src',src);
	},function(){
		$(this).css('text-align','left')
		var src = $(this).attr('charset');
		$(this).children('img').attr('src',src);
	})
	
	/* 点击删除 */
	$(".weibo_delete").click(function(){
		
		par = $(this).parent().parent().parent().parent();
		$.get($(this).attr('href'),function(data){

			if (data == '1')
			{
				$(par).hide(300,function(){
				$(par).remove();
				});
			}
			else
			{
				alert('删除失败!');
			}
		})
		return false;
	})
})

/* 字数检查 */
function slength_t(obj)
{
	var curLength=$(obj).val().length;
	if(curLength >= slength){
		var num = $(obj).val().substr(0,slength);
		$(obj).val(num);
	}
	$(obj).next().children('span').children('font').html(slength - $(obj).val().length)
}

</script>
<div class="weibos">
<?php foreach ($list as $val){

if (empty($val['text']))
{
	$val['text'] = '转发：';
}

if (!empty($val['source']['id']))
{
	$id = $val['source']['id'];
}
else
{
	$id = $val['id'];
}
$count[] = $val['id'];
?>
<div class="weibo weiboid_<?php echo $val['id'];?>">
	<img src="<?php echo $val['head'].'/50';?>" class="face"/>
	<ul>
		<li>
			<a href="#"><?php echo $val['nick'];?></a>: <?php echo $val['text'];?>
			<?php if (!empty($val['image'])){?>
				<div class="litpic" alt="<?php echo $val['image'][0].'/460';?>" charset="<?php echo $val['image'][0].'/160';?>">
					<img src="<?php echo $val['image'][0].'/160';?>"/>
				</div>
				<?php }?>
		</li>
		<?php if (!empty($val['source'])){
		$count[] = $val['source']['id'];
		?>
		<li>
			<div class="weibo_z">
				<a href="#"><?php echo $val['source']['nick'];?></a>: <?php echo $val['source']['text'];?>
				<?php if (!empty($val['source']['image'])){?>
				<div class="litpic" alt="<?php echo $val['source']['image'][0].'/460';?>" charset="<?php echo $val['source']['image'][0].'/160';?>">
					<img src="<?php echo $val['source']['image'][0].'/160';?>"/>
				</div>
				<?php }?>
			</div>
		</li>
		<?php }?>
		<li class="overflow">
			<span class="left">
			<a href="javascript:"><?php echo $this->load_fun('dtime',$val['timestamp'],2);?></a> 
			<a href="javascript:"><?php echo $val['from'];?></a></span>
			<span class="right">
				<a href="javascript:" class="zhuanfa" charset="zhuanfa_li">转发(<font class="rt_<?php echo $val['retweeted_status']['id'];?>">0</font>)</a> | 
				<a href="javascript:" class="pinglun" >评论(<font class="comments_<?php echo $val['retweeted_status']['id'];?>">0</font>)</a>  |  
				<?php if ($this->account['aid'] == $val['name']){?>
				<a href="/weibo/delete/<?php echo $val['id'];?>" class="weibo_delete">删除</a> |  
				<?php }?>
				<?php if (empty($act)){?>
				<a href="javascript:" onclick="favs(<?php echo $val['id'];?>,'add')">收藏</a>
				<?php }else{?>
				<a href="javascript:" onclick="favs(<?php echo $val['id'];?>,'del')">取消收藏</a>
				<?php }?>
				
		</li>
		<li class="zhuanfa_li">
		<form id="form1" name="form1" method="post" action="/weibo/repost" class="form1">
			<div class="weibo_zhuanfa ">
				<p>转发到我的微博 <a href="javascript:" class="del_zhuanfa">［删除之前的转发理由］</a><br>顺便说两句：</p>
				<textarea name="content" class="zhuanfa_body"> //@<?php echo $val['nick'];?> <?php echo $val['text'];?></textarea>
				<div class="zhuanfa_ps overflow">
					<input type="submit" value="转发"  class="button_blue yuan zhuanfa_but" tabindex="2">
					<input type="hidden" name="api" value="<?php echo $api;?>" />
					<input type="hidden" name="id" value="<?php echo $id;?>" />
					<span>还能输入<font id="num_ps">140</font>字</span>
				</div>
				<div class="zhuanfa_tips"></div>
			</div>
		</form>
		</li>
		<li class="pinglun_li" id="pinglun_<?php echo $val['id'];?>">
		<form id="form1" name="form1" method="post" action="/weibo/comment" class="form2">
			<div class="weibo_zhuanfa">
				<p>评论原文，评论内容不会发送给你的听众 <a href="javascript:" class="del_zhuanfa">［删除之前的转发理由］</a></p>
				<textarea name="content" class="zhuanfa_body comment_<?php echo $id;?>"> //@<?php echo $val['nick'];?> <?php echo $val['text'];?></textarea>
				<div class="zhuanfa_ps overflow">
					<input type="submit" value="评论"  class="button_blue yuan" tabindex="2">
					<input type="hidden" name="api" value="<?php echo $api;?>" />
					<input type="hidden" name="id" class="ids" value="<?php echo $id;?>" />
					<input type="hidden" name="cid" class="cid_<?php echo $id;?>" value="" />
					<span>还能输入<font id="num_ps">140</font>字</span>
				</div>
				<div class="zhuanfa_tips"></div>
				<div class="comment_list">
					<ul>
						
					</ul>
				</div>
			</div>
		</form>
		</li>
	</ul>
</div>
<?php }?>
</div>
<script>
/* 收藏 */
function favs(ids,act)
{

	$.post('/weibo/favorites_'+act+'/',{id:ids},function(data){
	
		if (act == 'del')
		{
			$(".weiboid_"+ids).hide(300);
		}
		tb_show('曹错评论','#TB_inline?height=100&width=200&inlineId=box_ps');
		tb_ps('操作成功！');
		setTimeout('tb_remove()',1000);
	})
	
	return false;
	//alert('a');
}
</script>